﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using WPFEdit.Util;

namespace WPFEdit.Document.Factory
{
    public class DocReaderFactory : InterfaceFactory<IDocumentReader, string, IDocumentReader, DocumentReaderAttribute>
    {
        public IDocumentReader GetReader(String extension)
        {
            IDocumentReader reader;
            m_factoryInstances.TryGetValue(extension, out reader);
            return reader;
        }

        protected override void AddType(Type type, object[] attributeInstances, ConstructorInfo constructorInfo)
        {
            DocumentReaderAttribute readderInfo = (DocumentReaderAttribute)attributeInstances[0];
            foreach (string extension in readderInfo.FileExtensions)
            {
                m_factoryInstances.Add(extension, (IDocumentReader)constructorInfo.Invoke(Reflection.EmptyObjects));
            }
        }
    }
}
